package com.xm.xmapp.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.xm.xmapp.R;
import com.xm.xmapp.app.CodeConstant;
import com.xm.xmapp.response.bean.ResponsePlieNetworkInfo;
import com.xm.xmapp.tools.StringTools;

public class SongCheDialog extends Dialog {

	private Context context;
	private OnSongCheDialog onSongCheDialog;
	private ResponsePlieNetworkInfo bean;


	public interface OnSongCheDialog {
		void yongche();

		void phone();
	}

	public void setOnSongCheDialog(OnSongCheDialog onSongCheDialog) {
		this.onSongCheDialog = onSongCheDialog;
	}

	public SongCheDialog(Context context, ResponsePlieNetworkInfo bean) {
		super(context, R.style.FenShiDialog);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.bean = bean;
	}

	@SuppressLint("InflateParams")
	public void init() {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.dialog_sendcar, null);

		view.findViewById(R.id.yongche).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {

						dismiss();
						if (onSongCheDialog != null)
							onSongCheDialog.yongche();

					}
				});

		view.findViewById(R.id.phone).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						dismiss();
						if (onSongCheDialog != null)
							onSongCheDialog.phone();

						if (bean.send_car_service_tel != null
								&& !bean.send_car_service_tel.equals("")) {
							Intent intent = new Intent(Intent.ACTION_CALL, Uri
									.parse("tel:" + bean.send_car_service_tel));
							context.startActivity(intent);
						} else {
							Intent intent = new Intent(Intent.ACTION_CALL, Uri
									.parse("tel:" + CodeConstant.phone));
							context.startActivity(intent);
						}

					}
				});

		view.findViewById(R.id.x).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						dismiss();

					}
				});

		setContentView(view);

		TextView send_car_service_tel, send_car_service_money, send_car_service_time, contact, note, juli;

		send_car_service_tel = (TextView) view
				.findViewById(R.id.send_car_service_tel);
		send_car_service_money = (TextView) view
				.findViewById(R.id.send_car_service_money);
		send_car_service_time = (TextView) view
				.findViewById(R.id.send_car_service_time);
		contact = (TextView) view.findViewById(R.id.contact);
		note = (TextView) view.findViewById(R.id.note);
		juli = (TextView) view.findViewById(R.id.juli);

		if (bean.send_car_service_time != null
				&& !bean.send_car_service_time.equals("")) {
			send_car_service_time.setText("服务时间：" + bean.send_car_service_time);
		}

		if (bean.send_car_service_tel != null
				&& !bean.send_car_service_tel.equals("")) {
			send_car_service_tel.setText(StringTools.getStyle(5,
					bean.send_car_service_tel, "送车热线："
							+ bean.send_car_service_tel));
		} else {
			send_car_service_tel.setText(StringTools.getStyle(5,
					CodeConstant.phone, "送车热线：" + CodeConstant.phone));
		}

		if (bean.send_car_service_money != null
				&& !bean.send_car_service_money.equals("")) {
			send_car_service_money.setText(StringTools.getStyle(8,
					bean.send_car_service_money + "元", "本次送车将收取您"
							+ bean.send_car_service_money + "元" + "服务费"));
		} else {
			send_car_service_money.setText(StringTools.getStyle(8, "20元",
					"本次送车将收取您" + "20元" + "服务费"));
		}

		if (bean.contact != null && !bean.contact.equals("")) {
			contact.setText(bean.contact);
		}

		if (bean.note != null && !bean.note.equals("")) {
			note.setText("注：" + bean.note);
		}

		if (bean.send_car_service_range > 0) {

			String str = StringTools.getJuliString(
					bean.send_car_service_range, 1000)+"";
			
			if(bean.send_car_service_range >= 1000)
			{
				str = "送车范围："+str+"km";
			}else
			{
				str = "送车范围："+str + "m";
			}
			
			
			juli.setText(str);
			juli.setVisibility(View.VISIBLE);

		} else {
			juli.setVisibility(View.GONE);
		}

		// juli

		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
		lp.width = (int) d.widthPixels; // 高度设置为屏幕的0.6
		lp.height = (int) d.heightPixels;
		dialogWindow.setAttributes(lp);
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		super.show();
		/** 3.自动弹出软键盘 **/

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		init();

	}
}
